package thread;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author Janson
 * @Date 2022/2/25 15:23
 * @Version 1.0
 */
//模拟网络延时， 放大问题的发生性
public class TestThreadSleep implements Runnable{
    @Override
    public void run() {
        while (true){
            int i = 10;
            for (; i >0; i--) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
            }
            if (i == 0)
                break;;
        }

    }

    public static void main(String[] args) throws InterruptedException {
        //TestThreadSleep testThreadSleep = new TestThreadSleep();
        //new Thread(testThreadSleep).start();
        Date date = new Date(System.currentTimeMillis());
        while (true){
            //ms 级别
            Thread.sleep(1000);
            int i = 0;
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
            i++;
            date = new Date(System.currentTimeMillis());
            if (i == 10)
                break;
        }
    }
}
